package com.lysj.bhp.supernode.service;

import com.lysj.bhp.supernode.base.SuperNodeContent;
import com.lysj.bhp.supernode.domain.SuperNode;
import com.lysj.bhp.supernode.domain.SuperNodeUser;
import com.lysj.bhp.util.web.ParamUtil;
import com.lysj.bhp.util.web.Resp;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional
public class SuperNodeUserService extends SuperNodeContent {

    public Resp remove(SuperNodeUser model) {
        if (ParamUtil.isBlack(model.getSuperNodeUserId())) {
            return new Resp(Resp.PARAM_ERROR, "请选择节点用户");
        }
        SuperNodeUser superNodeUser = superNodeUserRepository.findOne(model.getSuperNodeUserId());
        if (null == superNodeUser) {
            return new Resp(Resp.PARAM_ERROR, "节点用户错误!");
        }
        superNodeUserRepository.delete(model.getSuperNodeUserId());
        //超级节点用户数量-1
        if (!ParamUtil.isBlack(model.getSuperNodeId())) {
            SuperNode superNode = superNodeRepository.findOne(model.getSuperNodeId());
            superNode.setUserNumber(superNode.getUserNumber() - 1);
            superNodeRepository.save(superNode);
        }

        return new Resp("删除成功");
    }
}
